import sessionDAO from 'common/sessionDAO'
import RemoteDAO from 'common/RemoteDAO'
/**
 * 检查用户有没有登录，如果没有登录则会调用登录
 * @return {Boolean} [description]
 */
export default function () {
  var userCode = sessionDAO.getUserCode()
  var tgCode = sessionDAO.getTGCode()
  if (!userCode || userCode === '') {
    return RemoteDAO.callNativeLogin(tgCode).then(resp => {
      // sessionDAO.setUserCode(resp.data.user_code)
      return resp.data.user_code
    }).catch(error => {
      this.$store.dispatch('setTip', {text: error.message})
    })
  } else {
    return new Promise((resolve, reject) => {
      resolve(userCode)
    })
  }
}
